//
//  UIView+badge.m
//  HikingManager
//
//  Created by FENGYL on 2016/10/29.
//  Copyright © 2016年 FENGYL. All rights reserved.
//

#import "UIView+badge.h"


@implementation UIView (badge)

- (void)showBadgeDot{
    
    //移除之前的小红点
    [self removeBadge];
    
    //新建小红点
    UIView * badgeView = [[UIView alloc]init];
    badgeView.tag = 888 + self.tag;
    badgeView.layer.cornerRadius = 6;
    badgeView.backgroundColor = [UIColor redColor];
    CGRect viewFrame = self.frame;
    
    //确定小红点的位置
    CGFloat x = viewFrame.size.width - 7 ;
    badgeView.frame = CGRectMake(x, -3, 10, 10);
    [self addSubview:badgeView];
    
}

- (void)hideBadgeDot{
    
    //移除小红点
    [self removeBadge];
    
}

- (void)removeBadge{
    
    //按照tag值进行移除
    for (UIView *subView in self.subviews) {
        
        if (subView.tag == 888+self.tag) {
            
            [subView removeFromSuperview];
            
        }
    }
}

@end
